<?php

/**
 * This is the model class for table "asistencias".
 *
 * The followings are the available columns in table 'asistencias':
 * @property integer $id_asistencia
 * @property integer $id
 * @property integer $id_curso
 * @property integer $mes
 * @property string $fecha
 * @property string $asistencia_total
 * @property string $asistencia_requerida
 * @property string $ausencias
 *
 * The followings are the available model relations:
 * @property Cursos $idCurso
 * @property Profesores $id0
 */
class Asistencias extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'asistencias';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, id_curso, fecha, asistencia_total, asistencia_requerida, ausencias', 'required'),
			array('id, id_curso, mes', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id_asistencia, id, id_curso, mes, fecha, asistencia_total, asistencia_requerida, ausencias', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idCurso' => array(self::BELONGS_TO, 'Cursos', 'id_curso'),
			'id0' => array(self::BELONGS_TO, 'Profesores', 'id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_asistencia' => 'Id Asistencia',
			'id' => 'ID',
			'id_curso' => 'Id Curso',
			'mes' => 'Mes',
			'fecha' => 'Fecha',
			'asistencia_total' => 'Asistencia Total',
			'asistencia_requerida' => 'Asistencia Requerida',
			'ausencias' => 'Ausencias',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_asistencia',$this->id_asistencia);
		$criteria->compare('id',$this->id);
		$criteria->compare('id_curso',$this->id_curso);
		$criteria->compare('mes',$this->mes);
		$criteria->compare('fecha',$this->fecha,true);
		$criteria->compare('asistencia_total',$this->asistencia_total,true);
		$criteria->compare('asistencia_requerida',$this->asistencia_requerida,true);
		$criteria->compare('ausencias',$this->ausencias,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Asistencias the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	//TESTTESTTESTESTESTESTESTEST


 /*

 	  public function setAttributes ($values,$scenario='')
        {
                foreach ($this->dateAttributes() as $dateAttribute)
                {
                        if (is_array($values[$dateAttribute]))
                        {
                                $day = $values[$dateAttribute]['day'];
                                $month = $values[$dateAttribute]['month'];
                                $year = $values[$dateAttribute]['year'];

                                $values[$dateAttribute] = date('Y-m-d',mktime(0,0,0,$month,$day,$year));
                        }
                }

                parent::setAttributes($values,$scenario);
        }

    public function dateAttributes()
        {
                return array('expiryDate');
        }
*/
}
